﻿using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;
using System.Collections.Generic;
using System.Text;

namespace Pomelo.EntityFrameworkCore.MyCat.Metadata
{
    public class MycatEntityTypeAnnotations : RelationalEntityTypeAnnotations, IMycatEntityTypeAnnotations
    {
        /// <summary>
        ///     Constructs an instance for annotations of the given <see cref="IEntityType" />.
        /// </summary>
        /// <param name="entityType"> The <see cref="IEntityType" /> to use. </param>
        public MycatEntityTypeAnnotations([NotNull] IEntityType entityType)
            : base(entityType)
        {
        }

        /// <summary>
        ///     Constructs an instance for annotations of the <see cref="IEntityType" />
        ///     represented by the given annotation helper.
        /// </summary>
        /// <param name="annotations">
        ///     The <see cref="RelationalAnnotations" /> helper representing the <see cref="IEntityType" /> to annotate.
        /// </param>
        public MycatEntityTypeAnnotations([NotNull] RelationalAnnotations annotations)
            : base(annotations)
        {
        }

        /// <summary>
        ///     Indicates whether or not the type is mapped to a memory-optimized table.
        /// </summary>
        public virtual bool IsMemoryOptimized
        {
            get => Annotations.Metadata[MyCatFullAnnotationNames.Instance.MemoryOptimized] as bool? ?? false;
            set => SetIsMemoryOptimized(value);
        }

        /// <summary>
        ///     Attempts to set memory optimization.
        /// </summary>
        /// <param name="value"> The value to set. </param>
        /// <returns> <c>True</c> if the annotation was set; <c>false</c> otherwise. </returns>
        protected virtual bool SetIsMemoryOptimized(bool value)
            => Annotations.SetAnnotation(MyCatFullAnnotationNames.Instance.MemoryOptimized, value);
    }
}
